package com.tx.zlm_replay.controller;

import com.tx.zlm_replay.common.*;
import com.tx.zlm_replay.service.FileService;
import com.tx.zlm_replay.vo.AppAndStream;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author tx
 * @version 1.0
 * @date 2024/3/18 11:30
 * @description: 录像回放控制器
 */
@RestController
@Tag(name = "录像回放控制器")
@RequestMapping("/record")
@Slf4j
public class RecordController {
    @Resource
    private FileService filService;
    @Operation(description = "分页获取app+stream的列表")
    @GetMapping("/list")
    public RwithD<Page> getAppAndStreams(PageQuery query) {
        Page<AppAndStream> page = Page.buildPage(query);
        filService.getAppAndStreams(page);
        return RwithD.ok(page);
    }
    @Operation(description = "分页获取app列表")
    @GetMapping("/list")
    public RwithD<Page> getApps(PageQuery query) {
        Page<AppAndStream> page = Page.buildPage(query);
        filService.getAppAndStreams(page);
        return RwithD.ok(page);
    }
    @Operation(description = "分页stream列表")
    @GetMapping("/list")
    public RwithD<Page> getStreams(PageQuery query) {
        Page<AppAndStream> page = Page.buildPage(query);
        filService.getAppAndStreams(page);
        return RwithD.ok(page);
    }
    // 获取回放文件列表
    public void getFileInfoPage(Integer page, Integer count) {

    }

    @Operation(description = "获取回放日期列表")
    @Parameters({
            @Parameter(name = "app", description = "rtp"),
            @Parameter(name = "stream", description = "34020000001320000032_3402000000131000003"),
            @Parameter(name = "year", description = "2024"),
            @Parameter(name = "month", description = "1"),
    })
    @GetMapping("/date/list")
    public RwithD<List<String>> getFileDateList(@RequestParam String app,
                                                @RequestParam String stream,
                                                @RequestParam(required = false) String year,
                                                @RequestParam(required = false) String month

    ) {
        log.info("res:{}", RwithD.ok("hello"));
        if (app.equals("f")) {
            throw RException.info("异常");
        }

        return RwithD.ok(Arrays.asList("2024-01-01", app, stream, year+"-"+month));
    }
    // 播放回放
    // 下载回放
    // 回放历史记录清理
    // 回放历史文件合并
}
